﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.DAO;
using ClassLibrary.Data;
using System.Globalization;

public partial class UserControl_ucListProduct : System.Web.UI.UserControl
{
    TblProductsDAO ProductsDAO = new TblProductsDAO(Global.CONNECTION_STRING);
    TblPhoneBranDAO phoneBrandDAO = new TblPhoneBranDAO(Global.CONNECTION_STRING);
    TblModelDAO modelDAO = new TblModelDAO(Global.CONNECTION_STRING);
    TblJobsDAO JobsDAO = new TblJobsDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadProductsList();
            LoadPart();
        }
    }
    private void LoadProductsList()
    {
        grdProduct.DataSource = ProductsDAO.GetProductsList(2);
        grdProduct.DataBind();
    }

    private void LoadPart()
    {
        grdPart.DataSource = ProductsDAO.GetProductsList(1);
        grdPart.DataBind();
    }

    protected void btnModelDelete_Click(object sender, ImageClickEventArgs e)
    {
        // string id = Request.QueryString["id"];
        bool flag = false;
        try
        {

            //TblModel model = new TblModel();
            TblProducts product = new TblProducts();
            product.ProductID = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            int IDDelete = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            ProductsDAO.DeleteProduct(IDDelete);
            flag = true;
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE_ADMIN);
        }
        if (flag)
        {
            Response.Redirect("~/Admin/ListProducts.aspx");
        }
    }
    protected void grdProduct_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdProduct.PageIndex = e.NewPageIndex;
        LoadProductsList();
    }
    protected void btnDelete_Click(object sender, ImageClickEventArgs e)
    {
        bool flag = false;
        try
        {

            //TblModel model = new TblModel();
            TblProducts product = new TblProducts();
            product.ProductID = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            int IDDelete1 = Convert.ToInt32(((ImageButton)sender).CommandArgument);
            ProductsDAO.DeleteProduct(IDDelete1);
            flag = true;
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE_ADMIN);
        }
        if (flag)
        {
            Response.Redirect("~/Admin/ListProducts.aspx");
        }
    }
}
